home *** CD-ROM | disk | FTP | other *** search
/ Aminet 19 / Aminet 19 (1997)(GTI - Schatztruhe)[!][Jun 1997].iso / Aminet / dev / basic / MethodBBLib.lha / MethodBBLib / Examples / DTPictureExample.asc next >
Encoding:
Text File  |  1997-04-16  |  3.3 KB  |  166 lines

  1. ;Example code for MethodBBLib (C)opyRight 1997 by Erwan Fouret
  2.  
  3. ;##### IMPORTANT #####
  4. ;Include the resident 'blitzlibs:amigalibs.res'
  5. ;in 'Compiler->Compiler Options...'
  6.  
  7.  
  8. ;***** utility/tagitem.h *****
  9. #TAG_USER=(1 LSL 31)
  10.  
  11. ;***** datatypes/datatypesclass.h *****
  12. #DTA_Dummy=(#TAG_USER+$1000)
  13.  
  14. #DTA_LayoutProc=(#DTA_Dummy+27)
  15. #DTA_GroupID=(#DTA_Dummy+31)
  16. #DTA_SourceType=(#DTA_Dummy+101)
  17.  
  18. #DTST_FILE=2
  19.  
  20. ;***** datatypes/datatypes.h *****
  21. #GID_PICTURE=$70696374
  22.  
  23. ;***** datatupes/pictureclass.h ****
  24. NEWTYPE.BitMapHeader
  25.  bmh_Width.w
  26.  bmh_Height.w
  27.  bmh_Left.w
  28.  bmh_Top.w
  29.  bmh_Depth.b
  30.  bmh_Masking.b
  31.  bmh_Compression.b
  32.  bmh_Pad.b
  33.  bmh_Transparent.w
  34.  bmh_XAspect.b
  35.  bmh_YAspect.b
  36.  bmh_PageWidth.w
  37.  bmh_PageHeight.w
  38. End NEWTYPE
  39.  
  40. #PDTA_ModeID=(#DTA_Dummy+200)
  41. #PDTA_BitMapHeader=(#DTA_Dummy+201)
  42. #PDTA_ColorRegisters=(#DTA_Dummy+203)
  43.  
  44.  
  45. ;A little statement to transform bytes greater than 128 into words
  46. Statement adjust{*a.b}
  47.  v.w=Peek.w(*a)
  48.  If v<0
  49.   vv.w=v+256
  50.   Poke.w *a,vv
  51.  EndIf
  52. End Statement
  53.  
  54. NEWTYPE.tags a.l:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:t:u:v:w:x:y:z:End NEWTYPE
  55.  
  56. DEFTYPE.tags attrs
  57. DEFTYPE.BitMapHeader *bmhd
  58. DEFTYPE.l *vm
  59.  
  60. Dim *args.b(1)
  61.  
  62. rdargs.l=ReadArgs_("PIC/A",&*args(0),0) ;We read the args
  63.  
  64. If rdargs=0
  65.  PrintFault_ IoErr_(),"ShowDTPic" ;We display an error if no args
  66.  End
  67. EndIf
  68.  
  69. name$=Peek$(*args(0)) ;We get the name from the args
  70.  
  71. Print name$,":"
  72.  
  73. FreeArgs_ rdargs
  74.  
  75. attrs.tags\a=#DTA_SourceType,#DTST_FILE,#DTA_GroupID,#GID_PICTURE,0
  76.  
  77. *obj.b=NewDTObjectA_(&name$,attrs) ;We create the DT Object
  78.  
  79. If *obj=0
  80.  NPrint "Error creating DT Object !!!"
  81.  End
  82. EndIf
  83.  
  84. GetAttr_ #PDTA_BitMapHeader,*obj,&*bmhd
  85. GetAttr_ #PDTA_ModeID,*obj,&*vm
  86.  
  87. ;We get some informations on the picture
  88. ;And we print them
  89.  
  90. NPrint "(",*bmhd\bmh_Width,"x",*bmhd\bmh_Height,"x",*bmhd\bmh_Depth,")"
  91.  
  92. NPrint "ViewMode = $",Hex$(*vm)
  93.  
  94. w=*bmhd\bmh_Width
  95. h=*bmhd\bmh_Height
  96. d=*bmhd\bmh_Depth
  97.  
  98. If w<320 Then wi=320 Else wi=w
  99.  
  100. Screen 0,*bmhd\bmh_Left,*bmhd\bmh_Top,wi,h,d,*vm,"",1,2
  101.  
  102. *sc.Screen=Peek.l(Addr Screen(0))
  103. ;We get the address of our screen
  104.  
  105. *rp.RastPort=&*sc\_RastPort
  106. ;We get the address of our RastPort
  107.  
  108. ginfo.GadgetInfo\gi_Screen=*sc,0,0,*rp,*rp\Layer
  109. ginfo\gi_Domain\Left=*bmhd\bmh_Left,*bmhd\bmh_Top,w,h
  110. ginfo\gi_Pens\DetailPen=0,0
  111. ginfo\gi_DrInfo=GetScreenDrawInfo_(*sc)
  112.  
  113. ;We create a GadgetInfo structure
  114.  
  115. *gadinfo.GadgetInfo=&ginfo
  116.  
  117. attrs\a=#GA_Left,*bmhd\bmh_Left
  118. attrs\c=#GA_Top,*bmhd\bmh_Top
  119. attrs\e=#GA_Width,w
  120. attrs\g=#GA_Height,h
  121. attrs\i=#ICA_TARGET,#ICTARGET_IDCMP,0
  122.  
  123. SetDTAttrsA_ *obj,0,0,attrs
  124. ;We set some attrs to the Object
  125.  
  126. DoMethod *obj,#GM_LAYOUT,*gadinfo,0
  127. ;We draw the Picture on our screen
  128.  
  129. *isdrawn.l=0
  130.  
  131. Repeat                                     ;This loop
  132.  GetAttr_ #DTA_LayoutProc,*obj,&*isdrawn   ;wait for the end
  133. Until *isdrawn=0                           ;of the drawing of the pic
  134.  
  135. AGAPalRGB 0,((2^d)-1),0,0,0 ;init of the palette
  136.  
  137. *creg.b=0
  138.  
  139. GetAttr_ #PDTA_ColorRegisters,*obj,&*creg ;We get the color registers
  140.  
  141. For i=0 To ((2^d)-1)
  142.  r.b=Peek.b(*creg):g.b=Peek.b(*creg+1):b.b=Peek.b(*creg+2)
  143.  rr.w=r:gg.w=g:bb.w=b
  144.  adjust{&rr}:adjust{&gg}:adjust{&bb}
  145.  AGAPalRGB 0,i,rr,gg,bb
  146.  *creg=*creg+3
  147. Next
  148. ;This routine create the palette
  149.  
  150. ShowPalette 0
  151.  
  152. DoMethod *obj,#GM_RENDER,*gadinfo,*rp,1 ;We refresh the pic
  153.  
  154. Repeat
  155. Until Joyb(0)=2
  156.  
  157. ;We quit the prog
  158.  
  159. Free Palette 0
  160.  
  161. Free Screen 0
  162.  
  163. DisposeDTObject_ *obj
  164.  
  165. End
  166.